<?php

namespace common\models\db\tables;

use Yii;

/**
 * This is the model class for table "{{%equipment_app_version}}".
 *
 * @property string $id
 * @property string $app_version_id 唯一版本号
 * @property string $run_os 运行环境
 * @property string $tag 版本标识
 * @property string $title 更新标题
 * @property string $download_url 下载地址
 * @property int $must_update 强制更新
 * @property string $update_msg 更新信息
 * @property string $notify_msg 通知信息
 * @property int $status 状态
 * @property int $created_at
 * @property string $created_by
 *
 * @property Equipment[] $equipments
 * @property User $createdBy
 * @property EquipmentAppVersionUpdateLog[] $equipmentAppVersionUpdateLogs
 * @property EquipmentAppVersionUpdateLog[] $equipmentAppVersionUpdateLogs0
 */
class EquipmentAppVersion extends \yii\db\ActiveRecord
{
    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return '{{%equipment_app_version}}';
    }

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['app_version_id', 'run_os', 'tag', 'title', 'download_url', 'update_msg', 'notify_msg', 'created_at', 'created_by'], 'required'],
            [['must_update', 'status', 'created_at', 'created_by'], 'integer'],
            [['update_msg', 'notify_msg'], 'string'],
            [['app_version_id'], 'string', 'max' => 191],
            [['run_os', 'tag', 'title', 'download_url'], 'string', 'max' => 255],
            [['app_version_id'], 'unique'],
            [['created_by'], 'exist', 'skipOnError' => true, 'targetClass' => User::className(), 'targetAttribute' => ['created_by' => 'id']],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'id' => Yii::t('app', 'ID'),
            'app_version_id' => Yii::t('app', '唯一版本号'),
            'run_os' => Yii::t('app', '运行环境'),
            'tag' => Yii::t('app', '版本标识'),
            'title' => Yii::t('app', '更新标题'),
            'download_url' => Yii::t('app', '下载地址'),
            'must_update' => Yii::t('app', '强制更新'),
            'update_msg' => Yii::t('app', '更新信息'),
            'notify_msg' => Yii::t('app', '通知信息'),
            'status' => Yii::t('app', '状态'),
            'created_at' => Yii::t('app', 'Created At'),
            'created_by' => Yii::t('app', 'Created By'),
        ];
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getEquipments()
    {
        return $this->hasMany(Equipment::className(), ['app_version_id' => 'id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getCreatedBy()
    {
        return $this->hasOne(User::className(), ['id' => 'created_by']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getEquipmentAppVersionUpdateLogs()
    {
        return $this->hasMany(EquipmentAppVersionUpdateLog::className(), ['old_version_id' => 'id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getEquipmentAppVersionUpdateLogs0()
    {
        return $this->hasMany(EquipmentAppVersionUpdateLog::className(), ['new_version_id' => 'id']);
    }
}
